package com.example.aliyunsms.config;
import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * Created by IntelliJ IDEA2022.3.2
 * @Author: Tenghw
 * @Date: 2023/04/04  23:46
 * @Description:
 */
@Configuration
@EnableSwagger2
//@EnableKnife4j
//@EnableOpenApi
@SuppressWarnings("all")
public class Knife4jConfig {

    //配置基本信息
    @Bean
    public ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("用Knife4j构建的开发接口API文档")
                .description("restful接口风格 ")
                .termsOfServiceUrl("localhost:8083")
                .contact(new Contact("tenghw", "https://gitee.com/tenghuawei", "1073932229@qq.com"))
                .version("1.0.0")
                .build();
    }
    //配置文档生成
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                //加了@ApiOperation注解的类，生成接口文档
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                //加了@RestController注解的类，生成接口文档
                //.apis(RequestHandlerSelectors.withClassAnnotation(RestController.class))
                //包下的类，生成接口文档
                //.apis(RequestHandlerSelectors.basePackage("com.example.aliyunsms.controller"))
                .paths(PathSelectors.any())
                .build()
                // 分组名称
                .groupName("sms-group")
                .directModelSubstitute(java.util.Date.class, String.class);
               //.securitySchemes(security());
    }



//    private List<ApiKey> security() {
//        return newArrayList(
//                new ApiKey(Constant.TOKEN_HEADER, Constant.TOKEN_HEADER, "header")
//        );
//    }

}
